<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- Copyright 2016-2017 Steinar Bang                                                -->
<!--                                                                                 -->
<!-- Licensed under the Apache License, Version 2.0 (the "License");                 -->
<!-- you may not use this file except in compliance with the License.                -->
<!-- You may obtain a copy of the License at                                         -->
<!--   http://www.apache.org/licenses/LICENSE-2.0                                    -->
<!-- Unless required by applicable law or agreed to in writing,                      -->
<!-- software distributed under the License is distributed on an "AS IS" BASIS,      -->
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.        -->
<!-- See the License for the specific language governing permissions and limitations -->
<!-- under the License.                                                              -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Ukel�nn</title>
        <style type="text/css">
            .ui-widget {
            font-size: 300%;
            }
            .ui-widget .ui-widget {
            font-size: 100%;
            }
        </style>
    </h:head>
    <h:body>
        <f:event type="preRenderView" listener="#{ukelonn.redirectAdministratorsToAdminPage}" />
        <h1>Hei #{ukelonn.fornavn}!</h1>

        <f:view>
            <h:form id="balanse">
                <p:panelGrid columns="2">
                    <h:outputLabel for="balanse" value="Til gode:" />
                    <h:inputText id="balanse" value="#{ukelonn.balanse}" required="true"/>
                </p:panelGrid>
            </h:form>
            <p:accordionPanel id="userinfo" multiple="true">
                <p:tab title="Registrere jobb">
                    <h:form id="registrerjobb">
                        <p:panelGrid columns="2">
                            <p:selectOneMenu id="jobtype" value="#{ukelonn.newJobType}" converter="transactionTypeConverter" style="width:500px">
                                <f:selectItem itemLabel="Velg jobb" itemValue="" noSelectionOption="true" />
                                <f:selectItems value="#{ukelonn.jobTypes}" var="jobtype2" itemValue="#{jobtype2}" itemLabel="#{jobtype2.transactionTypeName}"/>
                                <p:ajax event="change" update="amount" listener="#{ukelonn.newJobTypeSelected}"/>
                            </p:selectOneMenu>
                            <h:inputText id="amount" value="#{ukelonn.newJobWages}" required="true" readonly="#{facesContext.currentPhaseId.ordinal eq 6}" style="width:auto"/>
                            <p:commandButton value="Registrer jobb" update="jobtype amount :balanse:balanse :userinfo:jobs:jobs :userinfo:payments:payments" actionListener="#{ukelonn.registerNewJob}" />
                        </p:panelGrid>
                    </h:form>
                </p:tab>
                <p:tab title="Siste jobber:">
                    <h:form id="jobs">
                        <p:dataTable id="jobs" var="job" value="#{ukelonn.jobs}" selection="${ukelonn.jobsSelectedForDelete}" rowKey="${job.id}" width="auto">
                            <p:columnGroup type="header">
                                <p:column style="width:16px;text-align:center" />
                                <p:column headerText="Dato" />
                                <p:column headerText="Jobbtype" />
                                <p:column headerText="Bel�p" />
                            </p:columnGroup>
                            <p:column selectionMode="multiple" />
                            <p:column><h:outputText value="#{job.transactionTime}"/></p:column>
                            <p:column><h:outputText value="#{job.transactionType.transactionTypeName}"/></p:column>
                            <p:column><h:outputText value="#{job.transactionAmount}"/></p:column>
                        </p:dataTable>
                        <p:commandButton value="Slett valgte jobber" update="jobs :balanse:balanse" actionListener="#{ukelonn.deleteSelectedJobs}" />
                    </h:form>
                </p:tab>
                <p:tab title="Siste utbetalinger">
                    <h:form id="payments">
                        <p:dataTable id="payments" var="payment" value="#{ukelonn.payments}">
                            <p:columnGroup type="header">
                                <p:column headerText="Dato" />
                                <p:column headerText="Type utbetaling" />
                                <p:column headerText="Bel�p" />
                            </p:columnGroup>
                            <p:column><h:outputText value="#{payment.transactionTime}"/></p:column>
                            <p:column><h:outputText value="#{payment.transactionType.transactionTypeName}"/></p:column>
                            <p:column><h:outputText value="#{payment.transactionAmount}"/></p:column>
                        </p:dataTable>
                    </h:form>
                </p:tab>
            </p:accordionPanel>
        </f:view>
    </h:body>
</html>
